package com.goods.business.controller;

import com.goods.business.service.BusinessService;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.*;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/business")
public class BusinessController {

    @Autowired
    private BusinessService businessService;

    //加载分类数据
    @GetMapping("/productCategory/categoryTree")
    public ResponseBean categoryTree(Integer pageNum, Integer pageSize){

        PageVO<ProductCategoryTreeNodeVO> voPageVO = businessService.categoryTree(pageNum, pageSize);

        return ResponseBean.success(voPageVO);
    }

    //加载父级分类数据
    @GetMapping("/productCategory/getParentCategoryTree")
    public ResponseBean getParentCategoryTree(){
        List<ProductCategoryTreeNodeVO> productCategoryTreeNodeVOList = businessService.getParentCategoryTree();
        return ResponseBean.success(productCategoryTreeNodeVOList);
    }

    //添加分类
    @PostMapping("/productCategory/add")
    public ResponseBean add(@RequestBody ProductCategoryVO productCategoryVO){
        businessService.add(productCategoryVO);
        return ResponseBean.success();
    }

    //编辑: 根据id查询做回显
    @GetMapping("/productCategory/edit/{id}")
    public ResponseBean edit(@PathVariable Long id){
        ProductCategoryVO productCategoryVO = businessService.edit(id);
        return ResponseBean.success(productCategoryVO);
    }

    //修改
    @PutMapping("/productCategory/update/{id}")
    public ResponseBean update(@PathVariable Long id, @RequestBody ProductCategoryVO productCategoryVO){
        businessService.update(id, productCategoryVO);
        return ResponseBean.success();
    }

    //删除分类：如果有子类的话，一起删除
    @DeleteMapping("/productCategory/delete/{id}")
    public ResponseBean delete(@PathVariable Long id){
        businessService.delete(id);
        return ResponseBean.success();
    }

    //=======================================物资来源==================================================

    //带条件查询的物资来源分页列表展示
    @GetMapping("/supplier/findSupplierList")
    public ResponseBean findSupplierList(Integer pageNum, Integer pageSize, SupplierVO supplierVO){
        PageVO<SupplierVO> supplierVOPageVO = businessService.findSupplierList(pageNum, pageSize, supplierVO);
        return ResponseBean.success(supplierVOPageVO);
    }

    //添加物资来源
    @PostMapping("/supplier/add")
    public ResponseBean supplierAdd(@RequestBody SupplierVO supplierVO){
        businessService.supplierAdd(supplierVO);
        return ResponseBean.success();
    }

    //编辑物资来源
    @GetMapping("/supplier/edit/{id}")
    public ResponseBean supplierEdit(@PathVariable Long id){
        SupplierVO supplierVO = businessService.supplierEdit(id);
        return ResponseBean.success(supplierVO);
    }

    //更新用户物资来源
    @PutMapping("/supplier/update/{id}")
    public ResponseBean supplierUpdate(@PathVariable Long id, @RequestBody SupplierVO supplierVO){
        businessService.supplierUpdate(id, supplierVO);
        return ResponseBean.success();
    }

    //删除来源
    @DeleteMapping("/supplier/delete/{id}")
    public ResponseBean supplierDelete(@PathVariable Long id){
        businessService.supplierDelete(id);
        return ResponseBean.success();
    }

    //=======================================物资资料==================================================

    //加载物资列表
    @GetMapping("/product/findProductList")
    public ResponseBean findProductList(Integer pageNum, Integer pageSize, String name,  Long categoryId, String supplier, Integer status){
        PageVO<ProductVO> productVOPageVO = businessService.findProductList(pageNum, pageSize, name, categoryId, supplier, status);
        return ResponseBean.success(productVOPageVO);
    }

    //添加物资
    @PostMapping("/product/add")
    public ResponseBean productAdd(@RequestBody ProductVO productVO){
        businessService.productAdd(productVO);
        return ResponseBean.success();
    }

    //编辑物资
    @GetMapping("/product/edit/{id}")
    public ResponseBean productEdit(@PathVariable Long id){
        ProductVO productVO = businessService.productEdit(id);

        return ResponseBean.success(productVO);
    }

    //更新物资
    @PutMapping("/product/update/{id}")
    public ResponseBean productUpdate(@PathVariable Long id, @RequestBody ProductVO productVO){
        businessService.productUpdate(id, productVO);
        return ResponseBean.success();
    }

    //移除回收站
    @PutMapping("/product/remove/{id}")
    public ResponseBean productRemove(@PathVariable Long id){
        businessService.productRemove(id);
        return ResponseBean.success();
    }

    //从回收站恢复
    @PutMapping("/product/back/{id}")
    public ResponseBean productBack(@PathVariable Long id){
        businessService.productBack(id);
        return ResponseBean.success();
    }

    //删除物资
    @DeleteMapping("/product/delete/{id}")
    public ResponseBean productDelete(@PathVariable Long id){
        businessService.productDelete(id);
        return ResponseBean.success();
    }

    //物资添加审核
    @PutMapping("/product/publish/{id}")
    public ResponseBean productPublish(@PathVariable Long id){
        businessService.productPublish(id);
        return ResponseBean.success();
    }

    //=============================================物资入库（入库记录）========================================

    //入库单（入库记录）数据分页列表展示
    @GetMapping("/inStock/findInStockList")
    public ResponseBean findInStockList(Integer pageNum, Integer pageSize, InStockVO inStockVO){
        PageVO<InStockVO> inStockVOPageVO = businessService.findInStockList(pageNum, pageSize, inStockVO);
        return ResponseBean.success(inStockVOPageVO);
    }

    //查看入库单明细
    @GetMapping("/inStock/detail/{id}")
    public ResponseBean inStockDetail(@PathVariable Long id, Integer pageNum){
        InStockDetailVO inStockDetailVO = businessService.inStockDetail(id, pageNum);
        return ResponseBean.success(inStockDetailVO);
    }

    //移除回收站
    @PutMapping("/inStock/remove/{id}")
    public ResponseBean inStockRemove(@PathVariable Long id){
        businessService.inStockRemove(id);
        return ResponseBean.success();
    }

    //从回收站恢复
    @PutMapping("/inStock/back/{id}")
    public ResponseBean inStockBack(@PathVariable Long id){
        businessService.inStockBack(id);
        return ResponseBean.success();
    }

    //物资入库审核
    @PutMapping("/inStock/publish/{id}")
    public ResponseBean inStockPublish(@PathVariable Long id){
        businessService.inStockPublish(id);
        return ResponseBean.success();
    }

    //删除明细
    @GetMapping("/inStock/delete/{id}")
    public ResponseBean inStockDelete(@PathVariable Long id){
        businessService.inStockDelete(id);
        return ResponseBean.success();
    }

    //===================================================添加入库单（物资入库）=========================================

    //加载来源数据
    @GetMapping("/supplier/findAll")
    public ResponseBean findAll(){
        List<SupplierVO> supplierVOList = businessService.findAll();
        return ResponseBean.success(supplierVOList);
    }

    //加载商品列表(可入库)
    @GetMapping("/product/findProducts")
    public ResponseBean findProducts(Integer pageNum, Integer pageSize, String categorys){
        PageVO<ProductVO> productVOPageVO = businessService.findProducts(pageNum, pageSize, categorys);
        return ResponseBean.success(productVOPageVO);
    }

    //添加入库单
    @PostMapping("/inStock/addIntoStock")
    public ResponseBean addIntoStock(@RequestBody InStockVO inStockVO){
        businessService.addIntoStock(inStockVO);
        return ResponseBean.success();
    }

    //加载库存信息
    @GetMapping("/product/findProductStocks")
    public ResponseBean findProductStocks(Integer pageNum, Integer pageSize, String name, String categorys){
        PageVO<ProductStockVO> productStockVOPageVO = businessService.findProductStocks(pageNum, pageSize, name, categorys);
        return ResponseBean.success(productStockVOPageVO);
    }

    //物资所有的库存信息
    @GetMapping("/product/findAllStocks")
    public ResponseBean findAllStocks(String name, String categorys){
        List<ProductStockVO> productStockVOList = businessService.findAllStocks(name, categorys);
        return ResponseBean.success(productStockVOList);
    }

    //==================================物资去处=====================================================

    //加载物资去处列表
    @GetMapping("/consumer/findConsumerList")
    public ResponseBean findConsumerList(Integer pageNum, Integer pageSize, String address, String contact, String name){
        PageVO<ConsumerVO> consumerVOPageVO = businessService.findConsumerList(pageNum, pageSize, address, contact, name);
        return ResponseBean.success(consumerVOPageVO);
    }

    //添加物资去处
    @PostMapping("/consumer/add")
    public ResponseBean consumerAdd(@RequestBody ConsumerVO consumerVO){
        businessService.consumerAdd(consumerVO);
        return ResponseBean.success();
    }

    //编辑物资去处
    @GetMapping("/consumer/edit/{id}")
    public ResponseBean consumerEdit(@PathVariable Long id){
        ConsumerVO consumerVO = businessService.consumerEdit(id);
        return ResponseBean.success(consumerVO);
    }

    //修改物资去处
    @PutMapping("/consumer/update/{id}")
    public ResponseBean consumerUpdate(@PathVariable Long id, @RequestBody ConsumerVO consumerVO){
        businessService.consumerUpdate(id, consumerVO);
        return ResponseBean.success();
    }

    //删除物资去处
    @DeleteMapping("/consumer/delete/{id}")
    public ResponseBean consumerDelete(@PathVariable Long id){
        businessService.consumerDelete(id);
        return ResponseBean.success();
    }

    //================================物资出库（发放记录）====================================

    //出库单（发放记录）数据分页列表展示
    @GetMapping("/outStock/findOutStockList")
    public ResponseBean findOutStockList(Integer pageNum, Integer pageSize, String outNum, Integer type, Integer status){
        PageVO<OutStockVO> outStockVOPageVO = businessService.findOutStockList(pageNum, pageSize, outNum, type, status);
        return ResponseBean.success(outStockVOPageVO);
    }

    //查看发放单明细
    @GetMapping("/outStock/detail/{id}")
    public ResponseBean outStockDetail(Integer pageNum, @PathVariable Long id){
        OutStockDetailVO outStockDetail = businessService.outStockDetail(pageNum, id);
        return ResponseBean.success(outStockDetail);
    }

    //移除回收站
    @PutMapping("/outStock/remove/{id}")
    public ResponseBean outStockRemove(@PathVariable Long id){
        businessService.outStockRemove(id);
        return ResponseBean.success();
    }

    //从回收站恢复
    @PutMapping("/outStock/back/{id}")
    public ResponseBean outStockBack(@PathVariable Long id){
        businessService.outStockBack(id);
        return ResponseBean.success();
    }

    //删除明细
    @GetMapping("outStock/delete/{id}")
    public ResponseBean outStockDelete(@PathVariable Long id){
        businessService.outStockDelete(id);
        return ResponseBean.success();
    }

    //物资发放审核
    @PutMapping("/outStock/publish/{id}")
    public ResponseBean outStockPublish(@PathVariable Long id){
        businessService.outStockPublish(id);
        return ResponseBean.success();
    }

    //==========================================添加出库单（发放物资）=====================================

    //加载去向数据
    @GetMapping("/consumer/findAll")
    public ResponseBean consumerFindAll(){
        List<ConsumerVO> consumerVOList = businessService.consumerFindAll();
        return ResponseBean.success(consumerVOList);
    }

    //创建发放单
    @PostMapping("/outStock/addOutStock")
    public ResponseBean addOutStock(@RequestBody OutStockVO outStockVO){
        businessService.addOutStock(outStockVO);
        return ResponseBean.success();
    }

    //今日是否已签到
    @GetMapping("/health/isReport")
    public ResponseBean isReport(HttpServletRequest request){
        HealthVO healthVO = businessService.isReport();
        return ResponseBean.success(healthVO);
    }

    //打卡
    @PostMapping("/health/report")
    public ResponseBean report(@RequestBody HealthVO healthVO){
        businessService.report(healthVO);
        return ResponseBean.success();
    }

    //打卡历史记录
    @GetMapping("/health/history")
    public ResponseBean history(Integer pageNum, Integer pageSize){
        PageVO<HealthVO> healthVOPageVO = businessService.history(pageNum, pageSize);
        return ResponseBean.success(healthVOPageVO);
    }

}
